/**
 * 功能:TK_DEPARTMENTS Dao类
 * 开发人员:yaren
 * 创建时间:2012/4/21 20:57:36
 */
package com.towker.frame.dao.basicData;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.springframework.stereotype.Repository;
import com.towker.core.db.BaseDao;
import com.towker.frame.model.basicData.Departments;
import com.towker.frame.model.basicData.Depots;

@Repository
@SuppressWarnings("unchecked")
public class DepartmentsDao extends BaseDao<Departments, Long>
{
	@Override
	public Class getEntityClass()
	{
		return Departments.class;
	}
	
	public boolean checkExistsCode(String dep_code, Integer id) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("dep_code", dep_code);
		if (id != null & id > 0) {
			map.put("id", id);
		}
		Integer totalCount = (Integer) this.getSqlSessionTemplate().selectOne(getIbatisMapperNamespace() + ".checkExistsCode", map);
		if (totalCount == null) {
			return false;
		} else {
			return totalCount > 0;
		}
	}

	public Departments getByCode(String depCode) {
		String statementName = getIbatisMapperNamespace() + ".getByCode";
		Map params = new TreeMap<String, Object>();
		params.put("dep_code", depCode);
		List<Departments> departments = getSqlSessionTemplate().selectList(statementName, params);
		if (departments.size() > 0) {
			return departments.get(0);
		}
		return null;
	}
}